package icu.ac.kr.phonebook.provider;
 
import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;

import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable.Creator;
import android.util.Log;
 
		
	public class PacelableObject implements Parcelable{

		public HashMap<Integer,ReservedWork> work;
		
		public PacelableObject(){
		}
		
		public PacelableObject(HashMap<Integer,ReservedWork> work ){
			super();
	
			this.work = work;
			
		} 

		public static final Creator<PacelableObject> CREATOR = new Creator<PacelableObject>() 
		{          

			public PacelableObject createFromParcel(Parcel source) 
			{              
				
				PacelableObject reservedHashMapPacel = new PacelableObject();
				reservedHashMapPacel.work = new HashMap<Integer,ReservedWork>();
				
				int size = source.readInt();

		 		for (int i = 0; i < size ; i++)
				{
					int key = source.readInt();
					ReservedWork reserved = new ReservedWork();
					reserved.hour = source.readInt();
					reserved.workType = source.readString();
					reserved.comment = source.readString();
					reserved.mode = source.readInt();
					reservedHashMapPacel.work.put(key, reserved);
		 				
				}
		 			           
				return reservedHashMapPacel;
			}

			public PacelableObject[] newArray(int arg0) {
				// TODO Auto-generated method stub
				Log.d("PARCEL", "new Array called");
				
				return null;
			}

		};
		
		
		public int describeContents() {
			// TODO Auto-generated method stub
			return 0;
		}
		public void writeToParcel(Parcel dest, int flags) {
			// TODO Auto-generated method stub
			
			dest.writeInt(work.size());
			final int size =work.size();

		 	if ( size > 0)
			{
				Set <Integer> key = work.keySet();
				Integer iKey = 0;
				Iterator it = key.iterator();
				
				while(it.hasNext())
				{
				
					iKey = (Integer) it.next();
					dest.writeInt(iKey);
					ReservedWork reserved = work.get(iKey);
					dest.writeInt(reserved.hour);
					dest.writeString(reserved.workType);
					dest.writeString(reserved.comment);
					dest.writeInt(reserved.mode);
										
				}
			}
			
		}
		
	}
	
	
 